﻿//页面添加新控件

function newWindow_Control(c_id,c_left,c_top,c_width,c_height,control_type,inner_html){
      data_fld = control_type;
       newWin = new Ext.Panel
            ({
            layout:'fit',
            //id:c_id,
            resizeHandles:'n s',
            resizable :true,
            width:c_width,
            height:c_height,
            minWidth:1,
            minHeight:1,
            x:c_left,
            y:c_top,
            readerTo:Ext.getBody(),
            floating:true,
            frame:false,
            shadow:false,
            dataFld:data_fld,//control_type ,//'lyTextView',
            style:'border:1px solid #C0C0C0;',//style:'border-color: 1px solid red;',//#8db2e3 p.el.dom.style.backgroundColor
            shadowOffset:0,   
            //innerHTML:inner_html,
            //html:"<div align='center' style='background-color:#00000F'><img src='../MaterialLib/20111119124834.jpg' height='100%' align='middle' /></div>",
            html:inner_html,
            //bodyStyle:'background-color:#CCD1D7',//padding:4px 4px 4px 4px;border-color:#DBD4C2;',//F1F7F9 padding:5px 5px 5px 5px;display:block;
            border:false, 
//            items: [{
//        title: 'South Region is resizable',
//        region: 'south',     // position for region
//        height: 100,
//        split: true,         // enable resizing
//        minSize: 75,         // defaults to 50
//        maxSize: 150,
//        margins: '0 5 5 5'
//    }],
            draggable:{
                  insertProxy:false,
                  onDrag:function(e){
                     var pel = this.proxy.getEl();
                     this.x = pel.getLeft(true);
                     this.y = pel.getTop(true);
                     var s = this.panel.getEl().shadow;
                     if (s){
                           s.realign(this.x,this.y,pel.getWidth(),pel.getHeight());
                     }
                     this.panel.focus();
                  },
                  endDrag:function(e){
                     var offx =GetOffSetPostionXY().x;
                     var offy =GetOffSetPostionXY().y;
                     var new_px = this.x - offx;
                     var new_py = this.y - offy;
                     //1、x、y小于0、0，固定位置在0、0
                     if (new_px < 0)
                        new_px = 0;
                     if (new_py < 0)
                        new_py = 0;
                     //2、x大于窗体宽-控件宽，固定x值为窗体的x - 控件的x
                     var pl_design_x = document.getElementById("pl_DesignPage").style.pixelWidth - 2;
                     var view_x = this.panel.getWidth();
                     if (new_px > (pl_design_x - view_x))
                         new_px = parseInt(pl_design_x - view_x);
                     //3、y大于窗体宽-控件宽，固定x值为窗体的x - 控件的y
                     var pl_design_y = document.getElementById("pl_DesignPage").clientHeight - 2;
                     var view_y = this.panel.getHeight();
                     if (new_py > (pl_design_y - view_y))
                         new_py = parseInt(pl_design_y - view_y);
                         
                     //不能移出父窗口的范围
                     if (isInt(new_px) && isInt(new_py))
                         this.panel.setPosition(new_px,new_py);
                        //this.panel.setPosition(this.x - offx,this.y - offy);
                     this.panel.focus();
                  }
                },
            listeners: {
			    render: function(p) {
                			p.el.on("mousemove", function() {//添加事件   
                                            //alert(p.el.id);   
                                        });
                            p.el.on("click", function() {//添加事件   
                                            p.el.focus();
                                            p.el.setZIndex(p.el.zindex +100) ;
                                        });
                            p.el.on("dblclick", function() {//添加事件   
                                            //alert('这是一个双击事件！'); 
                                            newWindow_txt(p) ;
                                        });
                            p.el.on("mousedown", function() {//添加事件   
                                            //alert('这是一个鼠标压下事件！'); 
                                            //p.el.focus();  
                                        });
                            p.el.on("focus", function() {//添加事件   
                                            //alert('这是一个获得焦点事件！');
                                              //p.el.dom.style.borderWidth ="1px";
                                              //p.body.dom.bodyStyle='background-color:#CCD1D7;padding:15px 5px 5px 5px;border-color:#79725B;'
                                              //p.body.dom.bodyStyle='background:transparent url(../images/square.gif) no-repeat;';
                                              //p.body.dom.style.backgroundColor ="#0000FF";
                                              p.el.setZIndex(100000) ;
                                              //pl_page.doLayout(); 
                                        });
                            p.el.on("blur", function() {//添加事件   blur
                                            //alert('这是一个失去焦点事件！'); 
                                            //p.el.dom.style.borderWidth ="0px";
                                            //p.body.dom.style.backgroundColor ="#CCD1D7";
                                            p.el.setZIndex(100) ;
                                        });
                            p.el.on("keydown", function() {//添加事件   
                                            //alert('delete');
                                            var x = p.el;
                                            //x.remove();
                                            if(event.keyCode==46) 
                                            {
                                                pl_DesignPage.remove(this.id);
                                            }
                                        });
                            
				var resizer = new Ext.Resizable(this.getEl(), {
					//handles:'se',//se
					wrap:false,
					minWidth: 1,
					minHeight: 1,
					//maxWidth: 800,
					//maxHeight: 600,
					transparent:true,
					handles: 'all',
					//preserveRatio: true,
					//dynamic:true,
					//animate:true,
                    //easing: 'backIn',
                    //duration:.6,
					pinned: false
					
				});
				var t_id = this.getEl();//Ext.getCmp(c_id);//'imagepanel'+xi
                resizer.on('resize',resizeHandler,t_id);
               function resizeHandler(e) {      
                   var t = Ext.getCmp(t_id.id);         
                   var box = resizer.getEl().getSize();
                   //t.setSize( box );
                   var ly_width =t.getWidth();// resizer.getEl().dom.style.pixelWidth;
                   var ly_height = t.getHeight();//resizer.getEl().dom.style.pixelHeight;

                   //t.setSize(parseInt(ly_width),ly_height); //parseInt(ly_height)
                   var pl_design_x = document.getElementById("pl_DesignPage").style.pixelWidth - 2;//pl_DesignPage = pl_DesignPage +2
                   var pl_design_y = document.getElementById("pl_DesignPage").clientHeight - 2;//.style.pixelWidth - 
                   //不能大于父窗体的高和宽

                   if (ly_width > pl_design_x )
                       ly_width = pl_design_x;
                   if (ly_height > pl_design_y )
                       ly_height = pl_design_y;  
                   //t.setWidth(parseInt(ly_width));
                   //t.height = parseInt(ly_height);
                   //t.setHeight(parseInt(ly_height));
                   //t.body.dom.style.pixelHeight = parseInt(ly_height);
                   //t.setSize(parseInt(ly_width) ,parseInt(ly_height));
                   //resizer.getEl().setSize(resizer.getEl().dom.style.pixelWidth,resizer.getEl().dom.style.pixelHeight);
                   resizer.getEl().setSize(parseInt(ly_width),parseInt(ly_height));
                   t.syncSize();
                   t.enable = false;
                   t.enable = true;
                   var t_com = document.getElementById("design_flash_"+t_id.id);
                   if (t_com != null)
                   {
                       t_com.width=parseInt(ly_width);
                       t_com.height=parseInt(ly_height);
                   }
               }
                                 
			}
		    }
        });  

        pl_DesignPage.add(newWin);
        //添加组件完成后，调用下面的函数重新显示panel及组件

        pl_DesignPage.doLayout();
        newWin.show();  
        
        var arrdata_Fld = newWin.dataFld.split(";"); 
        var contrl_type = arrdata_Fld[0]; 
        if (contrl_type == "lyFlashView" && arrdata_Fld.length > 1)
        {
            LoadFlashFile(newWin.id,inner_html,c_width,c_height);
        } 
        
        newWin.focus();
    }
    
    
  
    //获取控件的偏移量
    function CPos(x, y)
    {
        this.x = x;
        this.y = y;
    }

    function GetOffSetPostionXY()
    {
        var target = document.getElementById("pl_DesignPage");
        var pos = new CPos(target.offsetLeft, target.offsetTop);
      
        var target = target.offsetParent;
        while (target)
        {
            pos.x += target.offsetLeft - target.scrollLeft;
            pos.y += target.offsetTop - target.scrollTop;
            
            target = target.offsetParent
        }
        return pos;
    }
    
function CreateNewControl(control_type)
{
     var sel_flag ='<div id ="sel_flag" style= "position:absolute;left:0;top:0; z-index:1000000; width:100%; height:100%;color:#000000;"> '
                 +' <div id="div_top" style="display:inline;float:left;  width:100%;">'
                 +' <div id="top_left" style="margin-top:0px;">■</div>'
                 +' <div id="top_center">■</div>'
                 +' <div id="top_right">■</div>'
                 +' </div>'
                 +' <div id="div_center" style="display:inline;float:left;width:100%;">'
                 +' <div id="center_left">■</div>'
                 +' <div id="Div3">&nbsp;</div>'
                 +' <div id="center_right">■</div>'
                 +' </div>'
                 +' <div id="div_bottom" style="display:inline;float:left;width:100%;">'
                 +' <div id="bottom_left">■</div>'
                 +' <div id="bottom_center">■</div>'
                 +' <div id="bottom_right">■</div>'
                 +' </div>'
//+' <ul> '
//+' <li style="text-align:left;">1</li><li>2</li><li style="text-align:right;">3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li>'
//+' </ul>';

                 +' </div> ';
     if (control_type =='lyTextView')
     {
         //inner_html ='<p style="padding:5px;font-family:arial;background:#A5B6C8;font-color:#aaabbb;font-size:13px;"> 这是一个文本显示区域</p>';
         inner_html =  " <div align=center style=background-color:#E4EBF3><img src=../Image/selfToolBar/pic_B04.jpg height=100% width=100% /></div>";
         newWindow_Control('0',100,100,200,200,'lyTextView',inner_html);//c_id,c_left,c_top,c_width,c_height,control_type,inner_html
     }  
     if (control_type =='lyImageView')
     {
         //inner_html ='<img src="../images/android/aa.jpg" width ="100%" height="100%" />';
         //inner_html ='<p style="font-family:arial;background:#A5B6C8;font-size:13px;"> 这是一个图片显示区域</p>';
         inner_html = "<div align=center style='background-color:#E4EBF3;display:block;'><img src=../Image/selfToolBar/pic_B02.jpg height=100% width=100% /></div>";
         newWindow_Control('0',100,100,200,200,'lyImageView',inner_html);//c_id,c_left,c_top,c_width,c_height,control_type,inner_html
     } 
     if (control_type =='lyVideoView')
     {
         //inner_html ='<p style="font-family:arial;color:#A5B6C8;font-size:13px;"> 这是一个视频显示区域</p>';
         inner_html = "<div align=center style=background-color:#E4EBF3><img src=../Image/selfToolBar/pic_B01.jpg height=100% width=100% /></div>";
         newWindow_Control('0',100,100,200,200,'lyVideoView',inner_html);//c_id,c_left,c_top,c_width,c_height,control_type,inner_html
     }
     if (control_type =='lyFlashView')
     {
         //inner_html ='<p style="font-family:arial;color:#A5B6C8;font-size:13px;"> 这是一个Flash显示区域</p>';
         inner_html = "<div align=center style=background-color:#E4EBF3><img src=../Image/selfToolBar/pic_B03.jpg height=100% width=100% /></div>";
         newWindow_Control('0',100,100,200,200,'lyFlashView',inner_html);//c_id,c_left,c_top,c_width,c_height,control_type,inner_html
     }
     if (control_type =='lyLivingVideoView')
     {
         inner_html =//"<DIV  style='display:block; filter:alpha(opacity=75);'> "
                    
                     "<div align=center style=background-color:#E4EBF3><img src=../Image/selfToolBar/pic_B05.jpg height=100% width=100% /></div>";
         newWindow_Control('0',100,100,200,200,'lyLivingVideoView',inner_html);//c_id,c_left,c_top,c_width,c_height,control_type,inner_html
     }
     if (control_type =='lyDateTimeView')
     {
         inner_html = "<div align=center style=background-color:#E4EBF3><img src=../Image/selfToolBar/pic_B06.jpg height=100% width=100% /></div>";
         newWindow_Control('0',100,100,200,200,'lyDateTimeView',inner_html);//c_id,c_left,c_top,c_width,c_height,control_type,inner_html
     }
     if (control_type =='lyWeatherForecastView')
     {
         inner_html = "<div align=center style=background-color:#E4EBF3><img src=../Image/selfToolBar/pic_B06.jpg height=100% width=100% /></div>";
         newWindow_Control('0',100,100,200,200,'lyWeatherForecastView',inner_html);//c_id,c_left,c_top,c_width,c_height,control_type,inner_html
     }
      
     if (control_type =='lyWeatherForeCast')
     {
         inner_html = "<div align=center style=background-color:#E4EBF3><img src=../Image/selfToolBar/pic_B07.jpg height=100% width=100% /></div>";
         var m = "<div style='z-index:900000;position:absolute; width:100%;height:80; left:0px;top:0px;FILTER:alpha(opacity=50);background-color:blue'></div>";
         inner_html03 = m+"<div> <OBJECT ID=video1 CLASSID='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA' HEIGHT=100% WIDTH=60%> "
                    +" <param name='_ExtentX' value='9313'>"
                    +" <param name='_ExtentY' value='7620'>"
                    +" <param name='DisplayMode' value='0'>"
                    +" <param name='AUTOSTART' value='1'>"
                    +" <param name='SHUFFLE' value='0'>"
                    +" <param name='PREFETCH' value='0'>"
                    +" <param name='NOLABELS' value='0'>"
                    +" <param name='SRC' value='../MaterialLib/20111206142749734.rmvb'>"
                    +" <param name='CONTROLS' value='Imagewindow'>"
                    +" <param name='CONSOLE' value='Clip1'>"
                    +" <param name='LOOP' value='0'>"
                    +" <param name='NUMLOOP' value='0'>"
                    +" <param name='CENTER' value='0'>"
                    +" <param name='MAINTAINASPECT' value='0'>"
                    +" <param name='BACKGROUNDCOLOR' value='#000000'>"
                    +" <param name='TransparentAtStart' value='0'>"
                    +" <param name='wmode' value='transparent'>" 
                    +" <embed SRC type='audio/x-pn-realaudio-plugin' CONSOLE='Clip1' CONTROLS='Imagewindow' HEIGHT='288' WIDTH='352' AUTOSTART='false' wmode='transparent'>"
                    +" </OBJECT></div>";
         inner_html99 ='<object codebase="http://www.apple.com/qtactivex/qtplugin.cab" HEIGHT=100% WIDTH=100% '
                   +' classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" viewastext'
                   +' type="application/x-oleobject"> '
                   +' <param name="url" value="../MaterialLib/20111206142749734.rmvb"> '
                   +' <param name="uiMode" value="None"> '
                   +' <embed src="../MaterialLib/a01.wma" '
                   +' <param name="WindowlessVideo" value="0">'
                   +'  showstatusbar="1"'
                   +' type="application/x-oleobject " '
                   //+' type="application/x-mplayer2" '
                   +' pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"></embed> '
                   +' </object>';
          inner_html3 ='<OBJECT id=video2 height=100% width=100% classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA>'
                   +' <PARAM NAME="_ExtentX" VALUE="13229">'
                   +' <PARAM NAME="_ExtentY" VALUE="847">'
                   +' <PARAM NAME="AUTOSTART" VALUE="-1">'
                   +' <PARAM NAME="SHUFFLE" VALUE="0">'
                   +' <PARAM NAME="PREFETCH" VALUE="0">'
                   +' <PARAM NAME="NOLABELS" VALUE="0">'
                   +' <PARAM NAME="SRC" VALUE="../MaterialLib/20111206142749734.rmvb">'
                   +' <PARAM NAME="CONTROLS" VALUE="controlpanel">'
                   +' <PARAM NAME="CONSOLE" VALUE="Clip1">'
                   +' <PARAM NAME="LOOP" VALUE="0">'
                   +' <PARAM NAME="NUMLOOP" VALUE="0">'
                   +' <PARAM NAME="CENTER" VALUE="0">'
                   +' <PARAM NAME="MAINTAINASPECT" VALUE="0">'
                   +' <param name="wmode" value="transparent">' 
                   +' <PARAM NAME="BACKGROUNDCOLOR" VALUE="#000000">'
                   +' </OBJECT>';
           inner_html0 ='<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="300" height="50" id="RP2">'
                   +' <param name="_ExtentX" value="10001">'
                   +' <param name="_ExtentY" value="1270">'
                   +' <param name="AUTOSTART" value="-1">'
                   +' <param name="SHUFFLE" value="0">'
                   +' <param name="PREFETCH" value="0">'
                   +' <param name="NOLABELS" value="-1">'
                   +' <param name="SRC" value="../MaterialLib/20111206142749734.rmvb">'
                   +' <param name="CONTROLS" value="ControlPanel,StatusBar">'
                   +' <param name="CONSOLE" value="clip1">'
                   +' <param name="LOOP" value="true">'
                   +' <param name="NUMLOOP" value="1">'
                   +' <param name="CENTER" value="0">'
                   +' <param name="MAINTAINASPECT" value="0">'
                   +' <param name="BACKGROUNDCOLOR" value="#000000">'
                   +' </object> ';
         newWindow_Control('0',100,100,200,200,'lyWeatherForeCast',inner_html);//c_id,c_left,c_top,c_width,c_height,control_type,inner_html
     }
}

function newTextWindow_Control(c_id,c_left,c_top,c_width,c_height,control_type,inner_html,ly_BackColor, p_text, p_style,ly_Rollmode, ly_Rollspeed)
{
    if (ly_Rollmode == "RLLEFT")
    {
        var innerHTML ="<div style='background-color:"+ly_BackColor+" width:100%;height:100%;'>"
                     +"    <marquee onMouseOut='this.start()' onMouseOver='this.stop()' direction='left' width=100% scrollamount="+ly_Rollspeed+">"
                     +"        <div style='"+p_style+"'>" + p_text+ "</div>"
                     +"    </marquee>"
                     +" </div>";
    }
    else if (ly_Rollmode == "RLTOP")
    {
        var innerHTML ="<div style='background-color:"+ly_BackColor+" width:100%;height:100%;'>"
                     +"    <marquee onMouseOut='this.start()' onMouseOver='this.stop()' direction='up' height=100% scrollamount="+ly_Rollspeed+">"
                     +"        <div style='"+p_style+"'>" + p_text+ "</div>"
                     +"    </marquee>"
                     +" </div>";
    }
    else
    {
        var innerHTML ="<div style='background-color:"+ly_BackColor+" width:100%;height:100%;'><div style='"+p_style+"'>" + p_text+ "</div></div>";
    }
    newWindow_Control(c_id,c_left,c_top,c_width,c_height,control_type,innerHTML);
}

function newVideoWindow_Control(c_id,c_left,c_top,c_width,c_height,control_type,Video_File)
{
    if (Video_File != "")
    {   
        var FileUrl = GetWebUrl()+"/MaterialLib/"+Video_File;
        var operStr = "<div style='z-index:900000;position:absolute; width:100%;height:100%; left:0px;top:0px;FILTER:alpha(opacity=0);background-color:#00000F'></div>";
        var innerHTML = operStr + '<div><object id="'+c_id+'_MediaPlayer" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" HEIGHT=100% WIDTH=100% '
                   +' classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" '
                   +' type="application/x-oleobject"> '
                   +' <param name="url" value="'+FileUrl+'"> '
                   +' <param name="uiMode" value="None"> '
                   +' <param name="EnableContextMenu" VALUE="-1"> '
                   //+' <param name="wmode" value="Opaque">'//transparent
                   //+' <param name="fullScreen" value="1">'
                   +' <param name="WindowlessVideo" value="1">'
                   +' <param name="BufferingTime" value="3">'
                   +' <param name="stretchToFit" value="1"> '
                   //<!--缓冲时间-->'
                   +' <embed '
                   +'  showstatusbar="1"'
                   //+' type="application/x-oleobject " '
                   //+' type="application/x-mplayer2" '
                   //+' pluginspage="http://www.microsoft.com/Windows/MediaPlayer/">'
                   +' </embed> '
                   +' </object></div>';
    }
    newWindow_Control(c_id,c_left,c_top,c_width,c_height,control_type,innerHTML);
}

//标记控件被选中
function ShowViewSelectionFlag()
{
 /*   <div id ="sel_flag" style= "position:absoulte;left:1000;top:10; top:300; z-index:1000000; width:300; height:300; background-color:Green; color:Blue; display:block;">
         <div id="div_top" style="display:inline;float:left;  height:300;">
             <div id="top_left">■</div>
             <div id="top_center">■</div>
             <div id="top_right">■</div>
         </div>
         <div id="div_center" style="display:inline;float:left;">
             <div id="center_left">■</div>
             <div id="Div3">&nbsp;</div>
             <div id="center_right">■</div>
         </div>
         <div id="div_bottom" style="display:inline;float:left;">
             <div id="bottom_left">■</div>
             <div id="bottom_center">■</div>
             <div id="bottom_right">■</div>
         </div>
     </div>
    */
}

function LoadFlashFile(c_id,flash_File,ly_width,ly_height)
{
    var t = Ext.getCmp(c_id);
    if (t != null)
    {
        var flashFile = "../MaterialLib/"+flash_File;
        var innerHtml =  "<div align=center style=background-color:#00000F;><object id='design_flash_"+c_id+"' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' "
                           + " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0'"
                           + " align='middle'> "
                           + " <param name='movie' value='about:blank' />"
                           + " <param name='quality' value='high' />"
                           + "<param name='wmode' value='transparent'>"
                           + " </object></div> ";
        t.body.dom.innerHTML =innerHtml;
        t.syncSize();
        var t_com = document.getElementById("design_flash_"+c_id);//Ext.getCmp("design_flash_"+c_id);
        if (t_com != null)
        {
            loadSWF(t_com,flashFile,parseInt(ly_width),parseInt(ly_height));
        }
    }
}

//function loadSWF(t_com,fsrc,fwidth,fheight){
//         t_com.LoadMovie(0, fsrc);//movie
//         t_com.width=parseInt(fwidth - 28);
//         t_com.height=parseInt(fheight - 10);
//         frame_number=t_com.CurrentFrame();
//        }

//1。1整数
//整数或者为空

function isIntOrNull(str){
    if(!isObj(str))//判断对象是否存在
    return 'undefined';
    return isNull(str)||isInt(str);
}
//必需是整数

function isInt(str){
    var reg = /^(-|\+)?\d+$/ ;
    return reg.test(str);
}
//1.2 小数
//小数或者为空

function isFloatOrNull(str){
    if(!isObj(str))//判 断对象是否存在

    return 'undefined';
    if(isInt(str))
    return true;
    return isNull(str)||isFloat(str);
}
//必需是小数

function isFloat(str){
    if(isInt(str))
    return true;
    var reg = /^(-|\+)?\d+\.\d*$/;
    return reg.test(str);
}


